/**
 * 
 */
package smallChanges.statements;

import smallChanges.Tokenization.TokenSet;
import smallChanges.util.HashCodeUtil;

public class SCFormalParameter extends MultiTokenCodeRange2D
{
	private String name;
	// Hibernate dependent type
	private SCType type;
	
	public SCFormalParameter(TokenSet tokenSet) {
	    super(tokenSet);
	}
	
	public String toString() {
		return type+" "+getName();
	}

	/**
	 * @return the name
	 */
	public String getName()
	{
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name)
	{
		this.name = name;
	}

	/**
	 * @return
	 * @see smallChanges.statements.SCType#getKind()
	 */
	public String getKind()
	{
		return type.getKind();
	}
	/**
	 * @return
	 * @see smallChanges.statements.SCType#isArrayType()
	 */
	public boolean isArrayType()
	{
		return type.isArrayType();
	}
	/**
	 * @param isArray
	 * @see smallChanges.statements.SCType#setArrayType(boolean)
	 */
	public void setArrayType(boolean isArray)
	{
		type.setArrayType(isArray);
	}
	/**
	 * @param kind
	 * @see smallChanges.statements.SCType#setKind(java.lang.String)
	 */
	public void setKind(String kind)
	{
		type.setKind(kind);
	}

	/**
	 * @return
	 * @see smallChanges.statements.SCType#getType()
	 */
	public SCType getType()
	{
		return type;
	}

	/**
	 * @param type
	 * @see smallChanges.statements.SCType#setType(java.lang.String)
	 */
	public void setType(SCType type)
	{
		this.type=type;
		getTokensInRange().merge(type);
		// TODO adjust boundaries???
	}
	
	public boolean equals(Object otherObj)
	{
		boolean retVal = true;
		if(this == otherObj)
		{
			return true;
		}
		if((otherObj == null) || (otherObj.getClass() != this.getClass()))
		{
			return false;
		}
	
		SCFormalParameter other = (SCFormalParameter) otherObj;
		
		if( !type.equals(other.type))
		{
			retVal = false;
		}
		if( (name == null || other.name == null) && (name != other.name) )
		{
			retVal = false;
		}

		if( name != null && other.name != null && !name.equals(other.name))
		{
			retVal = false;
		}
		return retVal;
	}
	
	public int hashCode() {
		int retVal = 0;
		retVal = HashCodeUtil.hash(retVal, type);
		retVal = HashCodeUtil.hash(retVal, name);

		return retVal;
	}

}